package ubi.quando.App;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

import org.osmdroid.util.GeoPoint;

public class Contact implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	String mName;
	String mId;
	GeoPoint mLocation;
	String mEmail;

	public Contact(String name, String id, GeoPoint location) {
		mName = name;
		mId = id;
		mLocation = location;
	}

	public String getName() {
		return mName;
	}

	public String getId() {
		return mId;
	}
	
	public void setLocation(GeoPoint location) {
		mLocation = location;
	}
	
	public GeoPoint getLocation() {
		return mLocation;
	}

	@Override
	public String toString() {
		return mName;
	}

	protected void writeObject(ObjectOutputStream out) throws IOException {
		out.writeObject(mName);
		out.writeObject(mId);
		out.writeObject(mEmail);
		out.writeObject(mLocation);
	}

	protected void readObject(ObjectInputStream in) throws IOException,
			ClassNotFoundException {
		Object temp = in.readObject();
		if (temp != null) {
			mName = (String) temp;
		}
		temp = in.readObject();
		if (temp != null) {
			mId = (String) temp;
		}
		temp = in.readObject();
		if (temp != null) {
			mEmail = (String) temp;
		}
		temp = in.readObject();
		if (temp != null) {
			mLocation = (GeoPoint) temp;
		}
	}

	@Override
	public boolean equals(Object o) {
		Contact other = (Contact) o;
		if (other.getName().equals(mName) && other.getId().equals(mId)) {
			return true;
		}
		return false;
	}
	
	@Override
	public int hashCode() {
		return mId.hashCode();
	}
	
	public String getEmail() {
		return mEmail;
	}
	
	public void setEmail(String email) {
		this.mEmail = email;
	}
}
